﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XiaLastorm.Sharpshooter
{
	/// <summary>
	/// 聊天记录
	/// </summary>
	public class ChatLog
	{
		/// <summary>
		/// 记录时间
		/// </summary>
		public DateTime Time { get; set; }
		/// <summary>
		/// 发送方用户
		/// </summary>
		public User From { get; set; }
		/// <summary>
		/// 接收方用户
		/// </summary>
		public User To { get; set; }
		/// <summary>
		/// 聊天内容
		/// </summary>
		public byte[] Content { get; set; }

		/// <summary>
		/// 生成 <see cref="ChatLog"/> class 的新实例。
		/// </summary>
		/// <param name="time">记录时间</param>
		/// <param name="from">发送方用户</param>
		/// <param name="to">接收方用户</param>
		/// <param name="content">聊天内容</param>
		public ChatLog(DateTime time, User from, User to, byte[] content)
		{
			if (time == null)
				throw new ArgumentNullException("time");
			if (from == null)
				throw new ArgumentNullException("from");
			if (to == null)
				throw new ArgumentNullException("to");
			if (content == null)
				throw new ArgumentNullException("content");
			Time = time;
			From = from;
			To = to;
			Content = content;
		}

		/// <summary>
		/// 生成 <see cref="ChatLog"/> class 的新实例。
		/// </summary>
		/// <param name="from">发送方用户</param>
		/// <param name="to">接收方用户</param>
		/// <param name="content">聊天内容</param>
		public ChatLog(User from, User to, byte[] content)
			: this(DateTime.Now, from, to, content)
		{ }

		public override string ToString()
		{
			return string.Format("{0} {1} :\r\n{2}", From, Time, Content);
		}
	}
}
